home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / smixw130.zip / DETECT.C next >
C/C++ Source or Header  |  1997-06-06  |  2KB  |  81 lines

  1. /*      SMIXW is Copyright 1995 by Ethan Brodsky.  All rights reserved.     */
  2.  
  3. /* ██ DETECT.C ████████████████████████████████████████████████████████████ */
  4.  
  5. #define TRUE  1
  6. #define FALSE 0
  7.  
  8. int detect_settings(int *baseio, int *irq, int *dma, int *dma16);
  9.   /* Detects sound card settings using BLASTER environment variable */
  10.   /* Parameters:                                                    */
  11.   /*   baseio    Sound card base IO address                         */
  12.   /*   irq       Sound card IRQ                                     */
  13.   /*   dma       Sound card 8-bit DMA channel                       */
  14.   /*   dma16     Sound card 16-bit DMA channel (0 if none)          */
  15.   /* Returns:                                                       */
  16.   /*   TRUE      Sound card settings detected successfully          */
  17.   /*   FALSE     Sound card settings could not be detected          */
  18.  
  19. /* ████████████████████████████████████████████████████████████████████████ */
  20.  
  21. #include <ctype.h>
  22. #include <dos.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26. #define DECIMAL 0
  27. #define HEX     1
  28.  
  29. static int get_setting(char *str, char id, int hex, int *value)
  30.   {
  31.     char *paramstart;
  32.     char buf1[128];
  33.     char buf2[128];
  34.  
  35.     strcpy(buf1, str);
  36.     if (strchr(buf1, id) != NULL)
  37.       {
  38.         paramstart = strchr(buf1, id) + 1;
  39.  
  40.         if (strchr(paramstart, ' ') != NULL)
  41.           *(strchr(paramstart, ' ')) = '\0';
  42.  
  43.         if (hex)
  44.           strcpy(buf2, "0x");
  45.         else
  46.           strcpy(buf2, "");
  47.  
  48.         strcat(buf2, paramstart);
  49.  
  50.         *value = strtoul(buf2, NULL, 0);
  51.         return(TRUE);
  52.       }
  53.     else
  54.       {
  55.         value = 0;
  56.         return(FALSE);
  57.       }
  58.   }
  59.  
  60. int detect_settings(int *baseio, int *irq, int *dma, int *dma16)
  61.   {
  62.     char blaster[128];
  63.  
  64.     if (getenv("BLASTER") == NULL)
  65.       {
  66.         *baseio = 0;
  67.         *irq    = 0;
  68.         *dma    = 0;
  69.         *dma16  = 0;
  70.         return (FALSE);
  71.       }
  72.  
  73.     strupr(strcpy(blaster, getenv("BLASTER")));
  74.  
  75.     if (!get_setting(blaster, 'A', HEX,     baseio)) return(FALSE);
  76.     if (!get_setting(blaster, 'I', DECIMAL, irq))    return(FALSE);
  77.     if (!get_setting(blaster, 'D', DECIMAL, dma))    return(FALSE);
  78.     get_setting(blaster, 'H', DECIMAL, dma16);
  79.  
  80.     return(TRUE);
  81.   }